package moodish.Junit;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import moodish.comm.ClientMessage;
import moodish.comm.ServerMessage;
import moodish.comm.ServerSideMessage.Type;
import moodish.dummy.ClientCommDummy;
import moodish.dummy.ServerCommDummy;

import org.junit.Before;
import org.junit.Test;

public class JUnitClientCommDummy {

	ClientCommDummy clientComm;
	ServerCommDummy serverComm;

	@Before
	public void setUp() throws Exception {
		clientComm = new ClientCommDummy();
		serverComm = new ServerCommDummy();

	}

	@Test
	public void test() {
		serverComm.start();
		clientComm.connect(null, "Joao");
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		clientComm.friendship("Sofia");
		clientComm.unfriendship("Sofia");
		clientComm.sendMoodishMessage("Happy");
		serverComm
				.getClientMap()
				.get("Joao")
				.getSendMessageList()
				.add(new ClientMessage("Joao", null,
						moodish.comm.ClientSideMessage.Type.MOODISH_MESSAGE));
		assertNotNull(clientComm.getNextMessage());

		 ServerMessage sm = new ServerMessage(Type.MOODISH_MESSAGE, "happy",
		 "Joao");
		 clientComm.getSendMessageList().add(sm);
		 assertFalse(clientComm.hasNextMessage());
		 assertTrue(clientComm.isConnected());

		 clientComm.disconnect();
		 clientComm.getSendMessageList().add(
		 new ServerMessage(Type.CLIENT_DISCONNECTED, "Joao", "Joao"));
		 try {
		 Thread.sleep(100);
		 } catch (InterruptedException e) {
		 e.printStackTrace();
		 }
		 assertFalse(clientComm.isConnected());
	}
}
